<template>
	<view :style="$s.view_color">
		<my-navbar :name="nav_title" back-url="index/order"></my-navbar>
		<mySign @confirm="confirm()" title="电子签名"></mySign>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	import $file from '@/common/file'
	import checkLogin from '@/mixins/loginCheck.js'
	import mySign from "../components/my-sign.vue"
	export default {
		components:{
			mySign
		},
		mixins:[checkLogin],
		data() {
			return {
				nav_title:'订单签名',
				order_info:{},
				img_data:"",
				post_data:{
					id:0,
					sign_path:'',
				},
			}
		},
		onLoad(option){
			if(option.id!=null){
				this.post_data.id=option.id
			}else{
				this.$c.error('缺少参数','index/index')
			}
		},
		onShow(){
			this.initData()
		},
		computed:{
			...mapState({
				gain_info:state => state.$gainInfo,
				back_info:state => state.$backInfo,
				start_date:state => state.$startDate,
				end_date:state => state.$endDate,
				carid:state => state.$carID,
			}),
		},
		methods: {
			initData(){
				this.$u.api.orderInfo({order_id:this.post_data.id}).then(res=>{
					this.order_info=res.data
				})
			},
			//提交订单
			confirm(path){
				uni.showModal({
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮文字 
					title: '签名确认',
					content: '您确认该签名无误吗？',
					success: con => {
						if (con.confirm) {
							uni.showLoading({
								title:"签名上传中..."
							})
							this.submit(path)
						}
					}
				})
			},
			async submit(path){
				//上传签名图片
				const upload_res = await $file.uploadImg(path)
				if(upload_res.data.url){
					this.post_data.sign_path=upload_res.data.url
					this.$u.api.orderSign(this.post_data).then(res=>{
						uni.hideLoading()
						if(res.status){
							this.$c.a("flow/"+res.data.url+"/index",{id:this.post_data.id},4)
						}
					}).catch(err=>{
						// 临时解决隐藏问题
						setTimeout(function(){
							uni.hideLoading()
						},3000)
					})
				}else{
					this.$c.info('生成图片失败！')
					setTimeout(function(){
						uni.hideLoading()
					},3000)
				}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #FFFFFF;
	}
</style>
